package com.zzw.conf;

import com.alibaba.druid.support.http.StatViewServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
/**
* @Athor:xiezhongjiang
* @Description:定义一些servlet使用
* @Date:2017/10/26 11:45
* @Since:1.0.0
*/
public class ServletConfig {
    @Autowired
    private DruidDataSourceProperties dataSourceProperties;
    /**
    * @Athor:xiezhongjiang
    * @Description:druid监控
    * @Date:2017/10/26 10:39
    * @Param:[]
    * @return org.springframework.boot.web.servlet.ServletRegistrationBean
    */
    @Bean
    public ServletRegistrationBean druidServlet() {
        ServletRegistrationBean reg = new ServletRegistrationBean();
        reg.setServlet(new StatViewServlet());
        reg.addUrlMappings(dataSourceProperties.getUrlMapping());
        reg.addInitParameter("allow", dataSourceProperties.getAllow());
        reg.addInitParameter("deny", dataSourceProperties.getDeny());
        reg.addInitParameter("loginUsername", dataSourceProperties.getLoginUsername());
        reg.addInitParameter("loginPassword", dataSourceProperties.getLoginPassword());
        return reg;
    }
}
